<template>
  <router-layout>
    <div class="lackyDraw">
      <Nodata v-if="isNoData"></Nodata>
      <div class="list">
        <van-list v-model="loading" :finished="finished" @load="onLoad" :offset="0">
          <van-cell v-for="item in activeDataList" :key="item.id">
            <div class="lacky-list" @click="openLink(item)">
              <van-row type="flex">
                <van-col>
                  <div class="list-img">
                    <img :src="item.file_path" v-if="item.file_path" width="100%" alt>
                    <!-- <img src="../../../static/img/noimg.png" v-else height="100%" alt=""> -->
                  </div>
                </van-col>
                <van-col>
                  <div class="list-right">
                    <div class="right-header">{{ item.vote_title }}</div>
                    <div class="base">
                      <div class="base-text">截止日期：{{ item.vote_endtime | formate_date }}</div>
                    </div>
                  </div>
                </van-col>
              </van-row>
            </div>
          </van-cell>
        </van-list>
      </div>
    </div>
  </router-layout>
</template>
<script>
import { vote_list } from "@/api/vote";
import moment from "moment";
import Nodata from "../public/nodata/Nodata"; // 导入暂无数据组件
import TitleItem from "../../components/public/title/title";
export default {
  name: "VoteHome",
  components: { Nodata, TitleItem },
  computed: {
    activeDataList: function () {
      return this.dataList.filter(function (item) {
        return item.close_status == 1
      })
    }
  },
  data() {
    return {
      isNoData: false,
      loading: false,
      finished: false,
      listQuery: {
        current: 1,
        limit: 5,
        company_id: localStorage.getItem("companyId") - 0 || 1
      },
      dataList: [],
      total: "",
      abc: ""
    };
  },
  filters: {
    formate_date(v) {
      return moment(v).format("YYYY/MM/DD");
    }
  },
  methods: {
    back() {
      this.$router.go(-1);
    },
    openLink(item) {
      if (item.vote_type == 1) {
        this.$router.push({
          // path: "/VoteTypeOne",
          path: "/VoteTypeTwo",
          query: {
            id: item.id
          }
        });
      }
      if (item.vote_type == 2) {
        this.$router.push({
          // path: "/VoteTypeTwo",
          path: "/VoteTypeThree",
          query: {
            id: item.id
          }
        });
      }
      if (item.vote_type == 3) {
        this.$router.push({
          path: "/VoteTypeThree",
          query: {
            id: item.id
          }
        });
      }
    },
    openLink1() {
      this.$router.replace("/LotteryMe");
    },
    //获取数据
    async initList() {
      let query = Object.assign({}, this.listQuery);
      let res = await vote_list(query);
      let result = res.data;
      if (result.status == 100) {
        this.dataList = result.data.rows;
        if (!result.data.results) {
          this.isNoData = true;
        }
      }
      this.loading = false;
      if (result.data.results <= this.dataList.length) {
        this.finished = true;
      }
    },
    onLoad() {
      setTimeout(() => {
        this.listQuery.limit += 2;
        this.initList();
      }, 1000);
    }
  },
  created() {
    this.initList();
  }
};
</script>
<style lang="scss" scoped>
@import "VoteHome";
</style>
